/**
 * 
 */
package com.pactera.integral.controller;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;
import com.pactera.integral.entity.Group;
import com.pactera.integral.service.GroupService;

/**
 * @author TempUser
 *
 */
@Controller
@RequestMapping("/adm/group")
public class GroupController extends GenericController{
	@Resource
	private GroupService groupService;
	
	/**
	 * 组列表
	 * @param param
	 * @param pageable
	 * @return Response
	 */
	@PostMapping("/page")
	@ResponseBody  
    public Response getGroupPage(@RequestBody HashMap<String,Object> param, Pageable pageable) {
    	Page<Group> page = groupService.pageGroup(param, pageable);
       
    	return this.normal(page); 
    }
	
	/**
	 * 添加或修改组
	 * @param group
	 * @return Response
	 */
	@RequestMapping(value = "/save",method = RequestMethod.POST)
	@ResponseBody
    public Response save(@RequestBody Group group) {
       
		return this.normal(groupService.saveGroup(group)); 
    }

	/**
	 * 组明细
	 * @param groupId
	 * @return
	 */
	@RequestMapping(value = "/groupDetails",method = RequestMethod.GET)
	@ResponseBody
	public Response getGroup(@RequestParam(value = "groupId", required = false) String groupId) {
		 
		 return this.normal(groupService.getGroup(groupId)); 
	} 
	
	/**
	 * 小组下拉列表
	 * @return
	 */
	@RequestMapping(value = "/allGroup",method = RequestMethod.GET)
	@ResponseBody
	public Response getAllGroup() {
	
	   return this.normal(groupService.getAllGroup()); 
	}

	@RequestMapping(value = "/delete",method = RequestMethod.GET)
	@ResponseBody
	public Response deleteGroup(@RequestParam(value = "groupId", required = false) String groupId,
	                            @RequestParam(value = "force", required = false) String force){

		return groupService.deleteGroup(groupId,force);
	}
}
